
package com.yimixian.app.rest.api;

import com.yimixian.app.common.CacheKeys;
import com.yimixian.app.common.Constants;
import com.yimixian.app.data.DataManager;
import com.yimixian.app.model.CommentReportResponse;
import com.yimixian.app.model.SearchKeyResult;
import com.yimixian.app.util.UiUtils;

import org.json.JSONObject;

import de.greenrobot.event.EventBus;
import retrofit.Callback;
import retrofit.client.Response;

import android.text.TextUtils;

/**
 * Created by songzy on 2015/10/26.
 */
public class CommentReportAPI extends YmxBaseAPI<CommentReportResponse> {

    public static final String COMMENT_REPORT = "/v5/commodity/comment/report";

    private String mCommentId;

    /**
     * @param callback
     */
    public CommentReportAPI(String commentId, Callback<Response> callback) {
        super(callback);
        mCommentId = commentId;
    }

    @Override
    public String getRelativeURL() {
        return COMMENT_REPORT;
    }

    public void commentReport() {
        String token = DataManager.getInstance().get(CacheKeys.TOKEN);
        if (TextUtils.isEmpty(token) || TextUtils.isEmpty(mCommentId)) {
            EventBus.getDefault().postSticky(new String(Constants.EVENT_BUS_DISSMISS_DIALOG));
            UiUtils.showToast("尚未登录，不能评论");
            return;
        }
        String commentId = mCommentId;
        mYmxRestService.commentReport(token, commentId, mCallback);
    }

    @Override
    public CommentReportResponse parseJson(JSONObject jsonObject) {
        CommentReportResponse commentReportResponse = new CommentReportResponse();
        if (jsonObject != null) {
            commentReportResponse.code = jsonObject.optInt("code");
            commentReportResponse.msg = jsonObject.optString("msg");
        }
        return commentReportResponse;
    }
}
